package cn.test.Async.demo;

import cn.test.Async.AsyncCall;

import java.util.concurrent.ExecutionException;
import java.util.concurrent.Future;
import static cn.test.Async.AsyncCall.threadName;

/**
 * create by zsunny
 * data: 2018/8/5
 **/
//利用future类
public class Demo3{

    private AsyncCall asyncCall = new AsyncCall();

    public Future<Long> call(){
        Future<Long> future = asyncCall.futureCall();
        asyncCall.shutdown();
        return future;

    }

    public static void main(String[] args) {

        Demo3 demo3 = new Demo3();

        System.out.println(threadName() +"发起调用");
        Future<Long> future = demo3.call();
        System.out.println(threadName() +"返回结果");

        while (!future.isDone() && !future.isCancelled());

        try {
            System.out.println(threadName() +future.get());
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }

        System.out.println(threadName() +"主线程内容");

    }
}
